package com.view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class user_window {
    private JFrame jFrame = new JFrame("图书管理系统");
    private JButton searchBookButton = new JButton("查询图书");
    private JButton borrowBookButton = new JButton("借阅图书");
    private JButton returnBookButton = new JButton("归还图书");
    private JButton myInfoButton = new JButton("我的信息");

    private Panel buttonPanel = new Panel();
    private Panel mainPanel = new Panel();

    private ScrollPane searchBookPane = new ScrollPane();
    private ScrollPane borrowBookPane = new ScrollPane();
    private ScrollPane returnBookPane = new ScrollPane();
    private ScrollPane myInfoPane = new ScrollPane();

    private JLabel searchBookLabel = new JLabel("searchBookLabel");
    private JLabel borrowBookLabel = new JLabel("borrowBook");
    private JLabel returnBookLabel = new JLabel("returnBook");
    private JLabel myInfoLabel = new JLabel("myInfo");

    private CardLayout cardLayout = new CardLayout();


    public void init(String username,String password) {
        jFrame.setBounds(200, 100, 1000, 600);
        jFrame.setLayout(new BorderLayout());
        mainPanel.setLayout(cardLayout);

        //添加按钮至按钮栏
        buttonPanel.add(searchBookButton);
        buttonPanel.add(borrowBookButton);
        buttonPanel.add(returnBookButton);
        buttonPanel.add(myInfoButton);

        //添加主页面
        mainPanel.add("查询图书", searchBookPane);
        mainPanel.add("借阅图书", borrowBookPane);
        mainPanel.add("归还图书", returnBookPane);
        mainPanel.add("我的信息", myInfoPane);

        //添加页面内容
        //searchBookPane.add(searchBookLabel);
        searchBookPane.add(new com.view.adminMenu.serchBookMenu().init());
        //borrowBookPane.add(borrowBookLabel);
        borrowBookPane.add(new com.view.userMenu.borrowBookMenu().init(username));
        //returnBookPane.add(returnBookLabel);
        returnBookPane.add(new com.view.userMenu.returnBookMenu().init(username));
        //myInfoPane.add(myInfoLabel);
        myInfoPane.add(new com.view.userMenu.myInfoMenu().init(jFrame,username,password));

        //创建事件监听器，监听按钮动作
        ActionListener listener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String actionCommand = e.getActionCommand();//字符串为按键上的文字
                switch (actionCommand) {
                    case "查询图书":
                        cardLayout.first(mainPanel);
                        System.out.println("clicked 查询图书");
                        break;
                    case "借阅图书":
                        cardLayout.show(mainPanel, "借阅图书");
                        System.out.println("clicked 借阅图书");
                        break;
                    case "归还图书":
                        cardLayout.show(mainPanel, "归还图书");
                        System.out.println("clicked 归还图书");
                        break;
                    case "我的信息":
                        cardLayout.last(mainPanel);
                        System.out.println("clicked 我的信息");
                        break;

                }
            }
        };

        //为按钮添加监听器
        searchBookButton.addActionListener(listener);
        borrowBookButton.addActionListener(listener);
        returnBookButton.addActionListener(listener);
        myInfoButton.addActionListener(listener);

        //组装jFrame
        jFrame.add(mainPanel, BorderLayout.CENTER);
        jFrame.add(buttonPanel, BorderLayout.SOUTH);
        jFrame.setVisible(true);

        }

//    public static void main(String[] args) {
//        new user_window().init("user1","123");
//    }
    }
